﻿package com.dg.gaming.api.common.playerstate
{
	import com.dg.gaming.api.common.Game;
	import com.dg.gaming.api.common.PlayerList;
	import com.dg.gaming.api.common.Table;
	import com.dg.gaming.api.common.util.DGLabels;

	/**
	 * ...
	 * @author
	 */
	public class PlayerStateViewing extends PlayerState
	{


		/**
		 * If a player sits the state changes to seated.
		 *
		 * @see com.dg.gaming.api.common.playerstate.PlayerState#sit()
		 */
		public override function sit():PlayerState
		{
			return new PlayerStateSeated();
		}

		/**
		 * A player can sit if the number of players already seated isn't greater
		 * than the maximum number of players allowed in this game.
		 *
		 * @see com.dg.gaming.api.common.playerstate.PlayerState#canSit(com.dg.gaming.api.common.PlayerList)
		 */
		public override function canSit(table:Table):Boolean
		{
			var numOfPlayers:int=table.getNumOfPlayers();
			// Count up the num of people seated (i.e. not simply viewing).
			var players:PlayerList=table.getPlayerList();
			var curPlayersSeated:int=players.getPlayerStateCount(SEATED) + players.getPlayerStateCount(GAME_STARTED) + players.getPlayerStateCount(READY_TO_START);

			return (curPlayersSeated < numOfPlayers);
		}

		// Defaults (do nothing)
		public override function stand():PlayerState
		{
			return this;
		}

		public override function start():PlayerState
		{
			return this;
		}

		public override function canStand(table:Table):Boolean
		{
			return false;
		}

		public override function canStart(table:Table, game:Game):Boolean
		{
			return false;
		}

		public override function canOfferDrawResign():Boolean
		{
			return false;
		}

		/**
		 * @see com.dg.gaming.api.common.playerstate.PlayerState#intValue()
		 */
		public override function stringValue():String
		{
			return VIEWING;
		}

		public override function toString():String
		{
			return DGLabels.getInstance().getValue("viewing");
		}


	}

}